package com.aaa.controller;


import com.aaa.entity.Singer;
import com.aaa.service.SingerService;
import com.aaa.util.SingerPageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/singer")
public class SingerController {
    @Autowired
    private SingerService singerService;
    private static final String IMG_PAGE="D:/upload/";
    @RequestMapping("/Select")
    public SingerPageInfo<Singer> Select(Integer pagesize, Integer currentpage, String inputm){
        SingerPageInfo<Singer> select = singerService.listAll(pagesize,currentpage,inputm);
        return select;
    }
    @RequestMapping("/Update")
    public Integer Update(Singer singer){
        Integer save = singerService.save(singer);
        return save;
    }

    @RequestMapping("/Delete")
    public Integer Update(Integer sid){
        Integer delete = singerService.delete(sid);
        return delete;
    }

    //图片上传
    @RequestMapping("/upload")
    public String upload(MultipartFile file){
        //生成唯一的文件名
        String imgname = UUID.randomUUID().toString();
        File file1=new File(IMG_PAGE+imgname);
        try {
            file.transferTo(file1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgname;
    }
}
